import Vue from "vue";
import Vuex from "vuex";

import request from "./modules/request";
import user from "./modules/user";
import app from "./modules/app";
import settings from "./modules/settings";
import permission from "./modules/permission";
import tabs from "./modules/tabs";
import createPersistedState from "vuex-persistedstate";
// 用户信息持久化
const userState = createPersistedState({
  reducer(val) {
    // console.log(val);

    return {
      user: {
        userInfo: val.user.userInfo,
        userPerm: val.user.userPerm
      },
      tabs: {
        tabsOption: val.tabs.tabsOption,
        tabsCurrentIndex: val.tabs.tabsCurrentIndex
      }
    };
  }
  // paths: ['user.userInfo','user.userPerm']
});
import getters from "./getters";

Vue.use(Vuex);

const store = new Vuex.Store({
  modules: {
    request,
    user,
    app,
    tabs,
    settings,
    permission
  },
  getters,
  plugins: [userState]
});

export default store;
